package cn.appsys.controller;


import cn.appsys.dao.devUserDao.DevUserMapper;
import cn.appsys.pojo.DevUser;
import cn.appsys.service.DevUserService;
import cn.appsys.tools.Constants;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/kaifa/")
public class ControllerKaifa {
@Resource
    DevUserService devUserService;
@Resource
    DevUserMapper devUserMapper;

    @RequestMapping("toLogin")
    public String dologin(Model model){
        return "login/devlogin";
    }

    @RequestMapping("yanzhengLogin")
    public String yanzhengLogin(@RequestParam("devCode")String username,
                                @RequestParam("devPassword")String password,
                                HttpSession session, Model model
                                ){
            DevUser devUser =new DevUser();

            devUser=  devUserService.LoginFlag(username,password);
            if(devUser==null || devUser.getDevPassword().equals("")|| !devUser.getDevPassword().equals(password)){


                model.addAttribute("error","用户名或密码错误！");
                return "login/devlogin";
            }else {

                session.setAttribute("devUser",devUser);
                return "Hellokaifa";
            }
    }

    @RequestMapping("loginOut")
    public String loginOut(HttpSession session){
        session.removeAttribute("devUser");

        return "index";
    }

}
